﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DataAccessLayer;
using DataAccessLayer.DAL;
using Common;

namespace BestBuy.UserViews
{
    public partial class BuyGoldMember : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            User user = UserDAL.GetUserByUsername(HttpContext.Current.User.Identity.Name);
            if (user != null)
            {
                LoadInfo(user);
            }
        }

        private void LoadInfo(User user)
        {
            Configuration confPrice = ConfigurationDAL.GetByName("GoldMemberPrice");
            lbPrice.Text = confPrice.Detail;
            Configuration confDay = ConfigurationDAL.GetByName("GoldMemberDay");
            lbDay.Text = confDay.Detail;
            lbDueTo.Text = user.GoldMemberDueTo.Value.ToShortDateString();
            lbConLai.Text = (user.GoldMemberDueTo.Value - DateTime.Today).Days.ToString();
        }

        protected void btnBuy_Click(object sender, EventArgs e)
        {
            User user = UserDAL.GetUserByUsername(HttpContext.Current.User.Identity.Name);
            if (user != null)
            {
                Configuration confDay = ConfigurationDAL.GetByName("GoldMemberDay");
                UserDAL.BuyGoldMember(user.ID, int.Parse(confDay.Detail));
            }
        }
    }
}